// 引入env中的url
const {
  baseUrl
} = require('./env').prod
// 专属域名
const subDomain = 'tongban-api-2'
module.exports = {
  /**二次封装wx.request()
   * url:请求的接口地址
   * method:请求方式
   * data传参
   * */
  request: (url, data = {},  method = 'GET',isSubDomain=true) => {
    let _url = `${baseUrl}/${isSubDomain?subDomain:''}${url}`
    return new Promise((resolve, reject) => {
      wx.showLoading({
        title:"正在加载"
      })
      wx.request({
        url: _url,
        data: data,
        method: method,
        header: {
          'content-type': 'application/json;charset=UTF-8',
          'door':'benxin'
        },
        success: (res) => {
          var status=res.data.status
          if(status==200){
            wx.hideLoading()
            resolve(res.data)
          }else if(status==700){
            wx.showToast({
              title: '接口错误',
            })
          }else if(status==701){
            wx.showToast({
              title: 'token错误',
            })
          }else if(status==702){
            wx.showToast({
              title: '参数验证错误',
            })
          }else if(status==800){
            wx.showToast({
              title: '系统维护',
            })
          }else{
            wx.showToast({
              title: '未知错误',
            })
          }
        }
      })
    })
  }

}

